package day21.zhiyou100;

import java.net.InetAddress;
import java.util.Arrays;

public class Demo01InetAddress {
    public static void main(String[] args) throws Exception {
            // InetAddress 网络地址类  LocalHost  本地主机
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);//PC-202303071213/192.168.217.212
        // 获取百度主机的主机信息
        InetAddress baiduHost = InetAddress.getByName("www.baidu.com");// String  host 对应的就是网络中的域名名称
        System.out.println(baiduHost);// www.baidu.com/110.242.68.3
        InetAddress[] baiduHosts = InetAddress.getAllByName("www.baidu.com");
        System.out.println(Arrays.toString(baiduHosts));//

        // 获取百度主机的主机名
        String hostName = baiduHost.getHostName();
        System.out.println(hostName);
        // 获取百度主机的IP地址
        String address = baiduHost.getHostAddress();
        System.out.println(address);// java.lang  110.242.68.4
        // public protected 默认不写  private

    }
}
